{template 'common/header'}
{if $do == 'display'}
<div class="clearfix">
	<div class="we7-padding-bottom clearfix">
		{if empty($module['main_module'])}
		<div class="pull-right">
			<a href="javascript:void(0);" data-toggle="modal" data-target="#user-modal" class="btn btn-primary we7-padding-horizontal">添加操作员</a>
		</div>
		{/if}
	</div>
	<table class="table we7-table table-hover">
		<thead class="navbar-inner">
		<tr>
			<th class="text-center" style="width:100px;">操作员名称</th>
			<th class="text-center" style="width:150px">权限信息</th>
			<th class="text-right" style="width:100px;">操作</th>
		</tr>
		</thead>
		<tbody>
		{if !empty($user_permissions)}
		{loop $user_permissions $item}
			<tr>
				<td class="text-center" style="width:50px;">{$item['user_info']['username']}</td>
				<td class="text-center">
					{if !empty($item['permission']) && !array_key_exists('all', $item['permission'])}
						{loop $item['permission'] $permission}
						<span class="label label-primary">{$permission}</span>
						{/loop}
					{else}
						<span class="label label-primary">所有</span>
					{/if}
				</td>
				<td style="width:100px;">
					<div class="link-group" >
						{if empty($module['main_module'])}
							<a href="{php echo url('module/permission/post', array('uid' => $item['uid'], 'm' => $module_name));}">编辑</a>
							<a href="{php echo url('module/permission/delete', array('uid' => $item['uid'], 'm' => $module_name));}" class="del">删除</a>
						{else}
							<span>---</span>
						{/if}
					</div>
				</td>
			</tr>
		{/loop}
		{else}
		<tr ng-if="!wechats">
			<td colspan="3" class="text-center">暂无数据</td>
		</tr>
		{/if}
		</tbody>
	</table>

	<!-- 添加应用操作员模态框 -->
	<div class="modal" id="user-modal">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<h3 class="modal-title">添加应用操作员</h3>
				</div>
				<form action="{php echo url('module/permission/add_clerk', array('m' => $module_name))}" method="post">
				<div class="modal-body we7-form">
					<div class="form-group">
						<label class="control-label col-sm-2"></label>
						<div class="col-sm-10">
							<input type="radio" id="addtype-1" name="addtype" value="{ACCOUNT_MANAGE_TYPE_OPERATOR}" checked>
							<label for="addtype-1" class="radio-inline">操作员</label>
							<a style="float: right" class="color-default"  href="{php echo url('module/permission/post', array('m' => $module_name))}">+添加用户</a>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">用户名</label>
						<div class="col-sm-10">
							<input id="add-username" name="username" type="text" class="form-control">
							<span class="help-block">请输入完整的用户名。</span>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<button type="submit" class="btn btn-primary" >确认</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				</div>
				</form>
			</div>
		</div>
	</div>

</div>
{/if}
{if $do == 'post'}
<div class="clearfix">
	<form action="" method="post" class="form-horizontal ajaxfrom we7-form" role="form" id="form-user">
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">用户名</label>
			<div class="col-sm-10 col-lg-9 col-xs-12">
				<input id="" name="username" type="text" class="form-control" value="{$user['username']}" />
				<span class="help-block">请输入用户名，用户名为 3 到 15 个字符组成，包括汉字，大小写字母（不区分大小写）</span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">密码</label>
			<div class="col-sm-10 col-lg-9 col-xs-12">
				<input id="password" name="password" type="password" class="form-control" value="" autocomplete="off" />
				<span class="help-block">请填写密码，最小长度为 8 个字符</span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">确认密码</label>
			<div class="col-sm-10 col-lg-9 col-xs-12">
				<input id="repassword" name="repassword" type="password" class="form-control" value="" autocomplete="off" />
				<span class="help-block">重复输入密码，确认正确输入</span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">备注</label>
			<div class="col-sm-10 col-lg-9 col-xs-12">
				<textarea id="" name="remark" style="height:80px;" class="form-control">{$user['remark']}</textarea>
				<span class="help-block">方便注明此用户的身份</span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">权限设置</label>
			<div class="col-sm-10 col-lg-10 col-xs-12">
				{loop $all_permission $key $module_val}
					<div class="col-sm-10 col-lg-10 col-xs-12 plugin-name">{$module_val['info']['title']}</div>
					{loop $module_val['permission'] $sub_key $permission}
					<div class="col-sm-4">
						<div class="checkbox">
							<input id="check-child-{$key}-{$sub_key}" type="checkbox" value="{$permission['permission']}" name="module_permission[{$module_val['info']['name']}][]" {if !empty($permission['checked'])}checked{/if}>
							<label for="check-child-{$key}-{$sub_key}">{$permission['title']}</label>
						</div>
					</div>
					{/loop}
				{/loop}
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-offset-2 col-md-offset-2 col-lg-offset-1 col-xs-12 col-sm-10 col-md-10 col-lg-11">
				<input type="submit" class="btn btn-primary span3" name="submit" value="提交" />
				<input type="hidden" name="token" value="{$_W['token']}" />
			</div>
		</div>
	</form>
</div>
<script>
var haveChecked = false;
$('input[type="checkbox"]').each(function(i, n) {
	if ($(n).prop('checked')) {
		haveChecked = true;
	}
});
if (!haveChecked) {
	$('input[type="checkbox"]').each(function(i, n) {
		$(n).prop('checked', 'checked')
	});	
}
</script>
{/if}
{template 'common/footer'}